from controller.order_controller import get_order, update_stock, add_product, read_file, write_file
from view.login_ui import login

def order_management_system():
    '''
    库存管理系统主程序
    :return:
    '''
    # 初始化文件名
    filename = "order.txt"
    # 读取库存文件
    order = read_file(filename)
    while True:
        print("\n请选择操作：")
        print("1. 用户登录")
        print("2. 查询库存")
        print("3. 修改库存")
        print("4. 添加新商品")
        print("5. 退出系统")
        choice = input("请输入操作编号：")
        if choice == "1":
            login()
        elif choice == "2":
            get_order(order)
        elif choice == "3":
            product_name = input("请输入商品名称：")
            new_stock = int(input("请输入新的库存数量："))
            update_stock(order, product_name, new_stock)
        elif choice == "4":
            product_name = input("请输入新商品名称：")
            stock_order = int(input("请输入库存数量："))
            add_product(order, product_name, stock_order)
        elif choice == "5":
            write_file(filename, order)
            print("退出系统，再见！")
            break
        else:
            print("无效输入，请重新选择！")
if __name__ == "__main__":
    order_management_system()
